<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>5-09 透明度</title>
</head>
<body>
  <canvas id="c" width="700" height="300" style="border: 1px solid #ccc;"></canvas>

  <script>
    const context = document.getElementById('c')
    const ctx = context.getContext('2d')

    const img = new Image()
    img.src = '../images/desert.jpg'

    img.onload = () => {
      ctx.drawImage(img, 10, 10)

      const imgData = ctx.getImageData(10, 10, 300, 200)

      const data = imgData.data

      for (var i = 0; i < data.length; i += 4) {
        data[i + 3] -= 100
      }

      ctx.putImageData(imgData, 340, 10)
    }
  </script>
</body>
</html>